<?php 
header("Content-Type:text/html;charset=utf-8");
include 'includes/init.php';
include_once 'includes/upload.class.php';
error_reporting(E_ERROR | E_PARSE);
session_start();

$id=isset($_SESSION['id'])?$_SESSION['id']:'';
$nphone = isset($_SESSION['phone']) ? $_SESSION['phone'] : '';
$uesrname = isset($_SESSION['uesrname']) ? $_SESSION['uesrname'] : '';
$time = time();


// 具体项目数据
if(!empty($_GET['project'])){
	$project = $_GET['project'];
	$code = $_GET['code'];

	$sql = "SELECT
			e.*, m.company_name
		FROM
			t_examine AS e,
			t_member AS m
		WHERE
			(
				m.company_data = e.company_data
				AND e.auditing = 1
				AND e.project = '".$project."'
				AND e.code = '".$code."'
			)
		OR (
			m.company_data = e.company_data
			AND e.auditing = 2
			AND e.project = '".$project."'
			AND e.code = '".$code."'
		)
		ORDER BY
			e.id DESC";

	$infoAll = $db_Obj->getall($sql);
	// 对比旧数据 旧数据与提交数据对比删除旧数据的重复部分.
 	$sql = "SELECT
		    m.company_name,
		    m.company_data,
		    p.mid,
		    p.nphone,
		    p.project,
		    p.status,
		    p.price_type,
		    p.lasttime,
		    p.units,
		    p.currency,
		    p.number,
		    p.material,
			p.purchase,
			p.plant,
			p.extranum,
			p.purchase_type,
		    b.price,
		    b.btype,
		    b.bsize,
		    b.delivery,
		    b.MOQ,
		    b.MPQ,
		    b.createtime,
		    b.bnumber,
		    b.rate,
		    b.id
		FROM
		    t_bid AS b,
		    t_member AS m,
		    t_product AS p
		WHERE
		(
				p.mifeng = 0 
				AND p.project = '".$project."'
				AND b.mid = m.id
				AND p.type = b.btype
			)
		OR (
			p.mifeng = 1
			AND p.lasttime < ".$time."
			AND p.project = '".$project."'
			AND b.mid = m.id
			AND p.type = b.btype
		)	
		ORDER BY p.type asc, b.price asc
		";
	$infoAll_bid = $db_Obj->getall($sql);
	foreach ($infoAll as $k_a => $v_a) {
		foreach ($infoAll_bid as $k_b => $v_b) {
			if($v_a['bid_id'] == $v_b['id']){
				unset($infoAll_bid[$k_b]);
			}			
		}
	}
	$new_infoAll = array_merge($infoAll, $infoAll_bid);
	
	/*---------------------记录LOG------------------------*/
	// code 可以区分一个项目一个记录
	$code = $new_infoAll[0]['code'];
	$sql = "select * from t_exa_log where project = '".$project."' and code = '".$code."' ";
	$exa_data = $db_Obj->getall($sql);
	/*-------------------------END------------------------*/
}


// 驳回更新
if(!empty($_POST['type'])){
	$type = $_POST['type'];
	$project = $_POST['project'];
	$note = $_POST['note'];

	// file_name
	$tarr = array(
	 		'filepath'=>'upload',
	 		'maxsize'=>'100',
	 		'allowmime'=>array(
				'image/jpeg',
                'image/jpg',
                'image/pjpeg',
                'image/gif',
                'image/png',
                'image/x-png',
                'application/msexcel',
                'application/vnd.ms-excel',
                'application/msword',
                'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
                'text/plain',
            ),
            'israndname'=>'1',
        );

	$upObj = new fileup($tarr); 
	// file_name
 	$file_name = $upObj->up('file_name');
 	if ($file_name == '') { // 若文件名为空则输出错误信息
 		echo 'msg= '.$upObj->geterror();
 	}
 	// 更新
 	$sql = "update t_examine set note = '".$note."', file_name = '".$file_name."', auditing = 1, progress = '经理' where project = '".$project."'  ";
 	$query = $db_Obj->query($sql);
 	if($query == true){
 		echo "<script>alert('操作成功!');window.history.go(-1);location.reload();</script>";
 	}
}

include 'pro-detail.html';

 ?>